// N 叉树的层序遍历
function levelOrder(root) {
  let result = []
  if (!root) return result

  let queue = [root]

  while (queue.length) {
    let level = []
    let len = queue.length
    for (let i = 0; i < len; i++) {
      let cur = queue.shift()
      if (cur) {
        level.push(cur.val)
        queue.push(...cur.children)
      }
    }
    result.push(level)
  }

  return result
}
